/**
 * 
 */
package org.gov.vis.data.dto;

import java.util.StringTokenizer;

/**
 * @author Vishwanath
 *
 */
public class TimeHolderDto {
	
	public static final String MERIDIAN_AM = "AM";
	public static final String MERIDIAN_PM = "PM";
	
	private String hour = "00" ;
	
	private String minute = "00";
	
	private String second = "00";
	
	private String meridian = MERIDIAN_AM;
	
	
	/**
	 * Method called to set the Time Details based on the passed Display Time
	 * @param _displayTime
	 */
	public void setTime(String _displayTime){
		
		StringTokenizer timeTokenizer = new StringTokenizer(_displayTime, ":");
		if(timeTokenizer.hasMoreTokens()){
			this.hour = timeTokenizer.nextToken();
		}
		if(timeTokenizer.hasMoreTokens()){
			this.minute = timeTokenizer.nextToken();
		}
		if(timeTokenizer.hasMoreTokens()){
			StringTokenizer meridianSplitter = new StringTokenizer(timeTokenizer.nextToken(), " ");
			
			if(meridianSplitter.hasMoreTokens()){
				this.second = meridianSplitter.nextToken();
			}
			
			if(meridianSplitter.hasMoreTokens()){
				this.meridian = meridianSplitter.nextToken();
			}
		}
	}//end setTime
	
	public String toString(){
		
		StringBuffer timeAppender = new StringBuffer(10);
		if(this.hour.length() == 1){
			this.hour = "0"+hour;
		}
		if(this.minute.length() == 1){
			this.minute = "0"+minute;
		}
		timeAppender.append(this.hour);		
		timeAppender.append(":");
		timeAppender.append(this.minute);		
		timeAppender.append(":");
		timeAppender.append(this.second);		
		timeAppender.append(" ");
		timeAppender.append(this.meridian);	
		
		return timeAppender.toString();
	}//end toString

	/**
	 * Method called to get the Time in the format of hh:MM:ss Meridian
	 * @return
	 */
	public String getDisplayTime(){
		return this.toString();
	}//end getDisplayTime
	
	/**
	 * @return the hour
	 */
	public String getHour() {
		return hour;
	}

	/**
	 * @param hour the hour to set
	 */
	public void setHour(final String hour) {
		this.hour = hour;
	}

	/**
	 * @return the minute
	 */
	public String getMinute() {
		return minute;
	}

	/**
	 * @param minute the minute to set
	 */
	public void setMinute(final String minute) {
		this.minute = minute;
	}

	/**
	 * @return the second
	 */
	public String getSecond() {
		return second;
	}

	/**
	 * @param second the second to set
	 */
	public void setSecond(final String second) {
		this.second = second;
	}

	/**
	 * @return the maridian
	 */
	public String getMeridian() {
		return meridian;
	}

	/**
	 * @param maridian the maridian to set
	 */
	public void setMeridian(final String meridian) {
		this.meridian = meridian;
	}
	
	

}
